<?php

namespace app\admin\model;

use think\Model;

class Litestoreshoporder extends Model
{
    // 表名
    protected $name = 'litestore_shoporder';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'play_status_text',
        'order_status_text',
        'play_time_text',
        'play_name_text'
    ];
    

    
    public function getPlayStatusList()
    {
        return ['0' => __('Play_status 0'),'1' => __('Play_status 1'),'2' => __('Play_status 2')];
    }     

    public function getOrderStatusList()
    {
        return ['0' => __('Order_status 0'),'1' => __('Order_status 1'),'2' => __('Order_status 2'),'3' => __('Order_status 3'),'4' => __('Order_status 4')];
    }     

    public function getPlayNameList()
    {
        return ['1' => __('Play_name 1'),'2' => __('Play_name 2'),'3' => __('Play_name 3')];
    }     


    public function getPlayStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['play_status']) ? $data['play_status'] : '');
        $list = $this->getPlayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOrderStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPlayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['play_time']) ? $data['play_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPlayNameTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['play_name']) ? $data['play_name'] : '');
        $list = $this->getPlayNameList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setPlayTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }






    public function shop()
    {
        return $this->belongsTo('Litestoreshop', 'litestore_shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function shopcategory()
    {
        return $this->belongsTo('Litestoreshopcategory', 'litestore_shopcategory_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }




    public function getplayUsername($id){

        $palyuser=User::get(['id'=>$id]);
        return $palyuser['username'];
    }

    public function getplayUserid($name){

        $palyuser=User::get(['username'=>array('like','%'.$name.'%')]);
        return $palyuser['id'];
    }



}
